import Analysis from "./component/analysis";
import DataOverview from "./NewComponents/DataOverview.vue";
import FansPortrait from "./component/FansPortrait";
import LiveDetail from "./NewComponents/LiveDetail";
import TalentVideo from "./component/talentVideo";
import CargoAnalysis from "./NewComponents/CargoAnalysis";
import Ecommerce from "./component/Ecommerce";
import VideoDetail from "./NewComponents/VideoDetail";
import liveRecord from "./component/liveRecord";
import FansAnalysis from "./NewComponents/FansAnalysis";
import liveData from "./component/liveData";
import StarMap from "./component/StarMap";
import VueQr from "vue-qr";
import KChart from "./NewComponents/KChart.vue";
import TextShowHidden from "./NewComponents/TextShowHidden.vue";
import talentDetails from "./talentDetails_Compare";
export default {
  components: {
    Analysis,
    FansPortrait,
    VueQr,
    TalentVideo,
    Ecommerce,
    liveRecord,
    liveData,
    StarMap,
    DataOverview,
    LiveDetail,
    CargoAnalysis,
    VideoDetail,
    FansAnalysis,
    KChart,
    TextShowHidden,
    talentDetails,
    item_id: ""
  },
  data() {
    return {
      authorId: "", //达人id
      FansDays: "30天", //粉丝趋势
      FabulousDays: "30天", //点赞趋势
      FansliveTime: "", //粉丝弹窗选择时间
      FabulousliveTime: "", //点赞弹窗选择时间
      FansStartEnd: {
        disabledDate: time => {
          return (
            time.getTime() < Date.now() - 180 * 24 * 60 * 60 * 1000 ||
            time.getTime() > Date.now()
          ); // 返回 所有时间 大于 当前时间
        }
      },
      FabulousStartEnd: {
        disabledDate: time => {
          return (
            time.getTime() < Date.now() - 180 * 24 * 60 * 60 * 1000 ||
            time.getTime() > Date.now()
          ); // 返回 所有时间 大于 当前时间
        }
      },
      startDate1: "",
      endDate1: "",
      startDate2: "",
      endDate2: "",
      activeName: "0",
      infoData: {},
      showBtn: true, //展开==收起
      showPopup: false, //更多按钮
      showKeFu: false,
      scareValue: 3, //口碑评分
      showMouthEchart: false,
      showFansEchart: false,
      showFabulousEchart: false,
      changeBoard: true,
      trendType: 1,
      finishLeft: false,
      //左侧echarts弹窗数据
      FansEchart: {
        xData: [],
        yData1: [],
        yData2: []
      },

      FabulousEchart: {
        xData: [],
        yData1: [],
        yData2: []
      },
      PraiseData: {},
      rateColor: ["#4f5058", "#4f5058", "#4f5058"],
      level1: 0,
      level2: 0,
      level3: 0,

      // 账号检测
      popupList: false,
      input02: "",
      roomLoading: false,
      table_data: [],
      consume: "",
      surplus: "",
      showInclude: false,
      index: 0,
      author_id: 0,

      //直播间检测
      showHotRoom: false,
      inputValue: "",
      table_data01: [], //达人搜索数据
      author_id01: 0,
      index01: 0,
      showInclude01: false,
      choiceValue: "6小时",
      custom: false, //时间自定义
      frequency: null, // 直播监测剩余次数
      pickeroptions: {
        disabledDate: time => {
          return time.getTime() < Date.now() - 24 * 60 * 60 * 1000; // 返回 所有时间 大于 当前时间
        }
      },
      switchValue: false, //直播提醒
      value1: [new Date(), new Date().getTime() + 24 * 60 * 60 * 1000],
      Hour: 6, //监控时间
      Start: "", //监控开始时间
      Stop: "", //监控结束时间
      liveMonitorData: null, //直播监测用户信息
      numberMonitorData: null, //账号检测用户信息
      noCopyClick: true,
      xData: [],
      TalentDetails_Contrast: [],
      taentNewData: [],
      isShowImg: "",
      surplusCount: "",
      showButton: false,
      showLoading1: false,
      detailsList: [],
      talentDetails: false,
      num: "",
      taentNewDataLength: "",
      num02: "",
      keyss: 0, //  一键提速 text
      tenmin: false, // 十分钟
      fivemin: false, // 五分钟
      showBall: true, //显示加速球
      speedIs: false,
      isOpacity: false,
      timeDown: "", //倒计时
      loopTime: "", //五分钟定时器
      loopTenTime: "", //十分钟定时器
      minute: "",
      secondS: "",
      textNum: "",
      timeAuthor: "",
      speedShowIs: "",
      speedShowTime: "",
      realTime: 0, //数据渠道，0历史数据，1 爬虫实时数据
      vipLevel: "",
      storeUpMask: false,

    };
  },
  computed: {
    sliceStr() {
      if (this.infoData.introduce != null) {
        return this.infoData.introduce.substring(0, 30) + "...";
      }
      return "";
    }
  },
  watch: {
    FansDays: function (newVal, oldVal) {
      if (newVal) {
        this.FansEchart.yData1 = [];
        this.FansEchart.yData2 = [];
        this.FansEchart.xData = [];
        this.getFansEchart();
      }
    },

    FabulousDays: function (newVal, oldVal) {
      if (newVal) {
        this.FabulousEchart.yData1 = [];
        this.FabulousEchart.yData2 = [];
        this.FabulousEchart.xData = [];
        this.getFabulousEchart();
      }
    },
    activeName: function (newVal, oldVal) {
      document.querySelector(
        ".el-tabs__content"
      ).scrollTop = document.documentElement.scrollTop = 0;
    },
    taentNewData() {
      this.taentNewDataLength = this.taentNewData.length;
    },
    timeDown(val) {

      if (val * 1000 < 1) {
        if (this.textNum == "1") {
          clearInterval(this.loopTime);
          this.$router.go(0)
        } else {
          clearInterval(this.loopTenTime);
          this.textNum = "";
          this.keyss = 0;
          this.fivemin = false;
          this.tenmin = false;
          this.speedIs = false;
          this.showBall = true;
        }

      }


    }
  },
  created() {
    this.vipLevel = localStorage.getItem('vipLevel');
    this.authorId = this.$route.params.id;

    if (this.$route.params.index) {
      this.activeName = this.$route.params.index;
    }
    this.getInfoData().then(() => {
      this.getInfoData1();
    });
    this.getFansEchart();
    this.getFabulousEchart();
    // this.getPublicPraiseTrend();
    this.showChangeList();
    this.GetLiveMonitoringUseNum();

    this.num = this.taentNewData.length;
    if (JSON.parse(localStorage.getItem("TalentDetails_Contrast")) == null) {
      localStorage.setItem("TalentDetails_Contrast", JSON.stringify([]));
      this.taentNewData = JSON.parse(
        localStorage.getItem("TalentDetails_Contrast")
      );
    }

  },
  mounted() {
    this.taentNewData = JSON.parse(
      localStorage.getItem("TalentDetails_Contrast")
    );
    this.num = this.taentNewData.length;

  },

  methods: {
    // 跳转购买续费
    toBuy(){ 
      let initLevel = this.upLevel(this.vipLevel);
      this.storeUpMask = false;
      let router = this.$router.resolve({
        path: `/talent_main/buy?l=${initLevel}`
      });
      window.open(router.href, "_blank");
    },
    upLevel(level){ //获取比当前等级大一级的vip级别
      let aLevel = '';
      if(level == 0 || level == 3){
        aLevel = 4;
      }else if(level == 4 || level == 5){ //vip和svip个人版触发权限判断时，都跳到svip，
        aLevel = 1;
      }else if(level == 1 || level == 2){
        aLevel = 2;
      }
      return aLevel;
    },
    toCollection(){
      this.storeUpMask = false;
      let router = this.$router.resolve({
        path: `/talent_main/collectionRoot`
      });
      window.open(router.href, "_blank");
    },
    /**=================================直播间检测================================== */
    liveJc(dataObj) {
      this.liveMonitorData = dataObj;
      this.showHotRoom = true;
    },
    choice(i) {
      this.choiceValue = i;
      if (this.choiceValue == "6小时") {
        this.Hour = 6;
      } else if (this.choiceValue == "12小时") {
        this.Hour = 12;
      } else if (this.choiceValue == "24小时") {
        this.Hour = 24;
      } else if (this.choiceValue == "48小时") {
        this.Hour = 48;
      }
      if (this.choiceValue == "自定义") {
        this.value1 = [new Date(), new Date().getTime() + 24 * 60 * 60 * 1000];
        this.Start = this.timestamp(this.value1[0] / 1000, "Y-M-D h:m:s");
        this.Stop = this.timestamp(this.value1[1] / 1000, "Y-M-D h:m:s");
        this.custom = true;
        this.Hour = 0;
        this.choiceValue = "24小时";
      } else {
        this.custom = false;
      }

      this.GetLiveMonitoringUseNum();
    },
    getLiveData(cpage) {
      this.liveTableData = [];
      let that = this;
      that.roomLoading = true;
      this.$axios
        .post("/api/author/search", {
          age: "不限",
          category: 0,
          city: "不限",
          fans: "不限", // 粉丝数范围
          favorite_count: "不限", //点赞数范围
          gender: 3,
          hint: "不限",
          is_shop: 0,
          is_top_sale: 0,
          keyword: this.inputValue,
          more_age: "不限",
          more_city: "不限",
          more_gender: 3,
          more_province: "不限",
          more_star: "不限",
          order_by: "desc",
          page: "1",
          pro_count: "不限",
          province: "不限",
          size: "20",
          sort: "totalfans",
          star: "不限",
          verify_type: "3",
          video_count: "不限" // 作品数
        })
        .then(response => {
          if (response.data.code == 0) {
            this.table_data01 = response.data.data;

            this.index01 = response.data.data[0].unique_id;
            this.author_id01 = response.data.data[0].author_id;
            this.roomLoading = false;
            this.showInclude01 = false;
          } else if (response.data.code == 1002) {
            this.showInclude = true;
            this.roomLoading = false;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 选择时间
    changeTime() {
      if (this.value1 == null) {
        this.frequency.useNum = 0;
        this.value1 = [];
      }
      if (this.value1.length == 0) {
        this.choiceValue = [];
      } else {
        this.choiceValue = this.date_format(this.value1[1] - this.value1[0]);
        this.Start = this.timestamp(this.value1[0] / 1000, "Y-M-D h:m:s");
        this.Stop = this.timestamp(this.value1[1] / 1000, "Y-M-D h:m:s");
        this.GetLiveMonitoringUseNum();
      }
    },
    //时分秒换算
    date_format(micro_second) {
      // 总秒数
      var second = Math.floor(micro_second / 1000);
      // 天数
      var day = Math.floor(second / 3600 / 24);
      // 小时
      var hr = Math.floor((second / 3600) % 24);
      // 分钟
      var min = Math.floor((second / 60) % 60);
      // 秒
      var sec = Math.floor(second % 60);
      return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
    },
    // 获取直播监测使用数量和剩余数量
    GetLiveMonitoringUseNum() {
      if (this.Start) {
        if (this.Start == this.Stop) {
          if (this.frequency) {
            this.frequency.useNum = 0;
            return;
          }
        }
      }
      this.$axios
        .post("/api/Live/GetLiveMonitoringUseNum", {
          Hour: this.Hour,
          Start: this.Start,
          Stop: this.Stop
        })
        .then(res => {
          if (res.data.code == 0) {
            this.frequency = res.data.data;
          }
        });
    },
    /**=================================直播间检测================================== */

    /** ==========================      账号检测    ===========================   */
    accountJc(itemObj) {
      this.numberMonitorData = itemObj;
      this.popupList = true;
      this.GetAuthorMonitorUseNum();
    },
    //选择达人
    choiceTalent(i, author_id) {
      this.index = i;
      this.author_id = author_id;
    },
    // 账号监测开始监测按钮事件
    accountMonitorFn() {
      // numberMonitorData:null,//账号检测用户信息
      this.SetAuthorMonitor();
      this.popupList = false;
    },
    // 获取剩余次数
    GetAuthorMonitorUseNum() {
      this.$axios.post("/api/Author/GetAuthorMonitorUseNum").then(res => {
        if (res.data.code == 0) {
          this.consume = res.data.data.consume;
          this.surplus = res.data.data.surplus;
        }
      });
    },
    SetAuthorMonitor() {
      this.$axios
        .post("/api/Author/SetAuthorMonitor", {
          AuthorId: this.numberMonitorData.authorId
        })
        .then(res => {
          if (res.data.code == 0) {
            this.$message({
              message: res.data.msg,
              duration: 2000,
              type: "success",
              offset: 154
            });
            this.showFabulousEchart = false;
          } else {
            this.$message({
              message: res.data.msg,
              duration: 2000,
              customClass: "includeMessage",
              offset: 154
            });
            this.showFabulousEchart = false;
          }
          this.GetAuthorMonitorUseNum();
        });
    },
    // 直播监测开始监测按钮事件
    liveMonitorFn() {
      // liveMonitorData:null, //直播监测用户信息
      this.$axios
        .post("/api/Live/LiveMonitor", {
          AuthorId: this.liveMonitorData.authorId,
          IsRemind: this.switchValue,
          Hour: this.Hour,
          Start: this.Start,
          Stop: this.Stop
        })
        .then(res => {
          if (res.data.code == 1001) {
            this.$message({
              message: res.data.msg,
              duration: 2000,
              customClass: "includeMessage",
              offset: 154
            });
            this.showHotRoom = false;
          }
          if (res.data.code == 0) {
            this.$message({
              message: res.data.msg,
              duration: 2000,
              type: "success",
              offset: 154
            });
            this.showHotRoom = false;
          }
        });
    },
    /**             以上是账号检测            */

    toLiveDetails(e, id) {
      if (e != 1) return;
      let router = this.$router.resolve({
        path: `/live/${id}`
      });
      window.open(router.href, "_blank");
    },
    getData(e) {
      this.activeName = e;
    },
    FansPicker() {
      this.FansDays = "";
      this.FansEchart.yData1 = [];
      this.FansEchart.yData2 = [];
      this.FansEchart.xData = [];
      this.getFansEchart();
    },
    FabulousPicker() {
      this.FabulousDays = "";
      this.FabulousEchart.yData1 = [];
      this.FabulousEchart.yData2 = [];
      this.FabulousEchart.xData = [];
      this.getFabulousEchart();
    },
    showChangeList() {
      this.noCopyClick = false;
      this.$axios
        .get("/api/Author/GetPublicPraiseTrend", {
          params: {
            authorId: this.authorId,
            trendType: this.changeBoard ? 1 : 2
          }
        })
        .then(res => {
          this.xData = [];
          if (res.data.code == 0) {
            if (this.changeBoard == false) {
              res.data.data.name.forEach((item, i) => {
                // res.data.data.name = []
                let arr = item.substring(0, 2) + "月";
                this.xData.push(arr);
              });
            } else {
              this.xData = res.data.data.name;
            }
            this.scareValue = res.data.data.publicPraise;
            this.PraiseData = res.data.data;
            if (res.data.data.level == 1) {
              this.rateColor = ["#ea4759", "#ea4759", "#ea4759"];
            } else if (res.data.data.level == 2) {
              this.rateColor = ["#fd7f2c", "#fd7f2c", "#fd7f2c"];
            } else {
              this.rateColor = ["#4f5058", "#4f5058", "#4f5058"];
            }
            setTimeout(() => {
              this.noCopyClick = true;
            }, 300);
          }
        });
    },
    boardClick(e) {
      if (this.changeBoard == e) return;
      if (this.noCopyClick) {
        this.changeBoard = e;
        this.showChangeList();
      }
    },

    // 获取左侧粉丝图表数据
    getFansEchart() {
      switch (this.FansDays) {
        case "近7天":
          this.endDate1 = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate1 = this.timestamp(
            Date.now() / 1000 - 86400 * 6,
            "Y-M-D"
          );
          break;
        case "30天":
          this.endDate1 = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate1 = this.timestamp(
            Date.now() / 1000 - 86400 * 29,
            "Y-M-D"
          );
          break;
        case "90天":
          this.endDate1 = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate1 = this.timestamp(
            Date.now() / 1000 - 86400 * 89,
            "Y-M-D"
          );
          break;
        default:
          this.startDate1 = this.FansliveTime[0];
          this.endDate1 = this.FansliveTime[1];
          break;
      }
      this.FansliveTime = [this.startDate1, this.endDate1];
      this.$axios
        .get("/api/Author/GetFansFavoriteTrend", {
          params: {
            AuthorId: this.authorId,
            trendType: 1,
            star_time: this.startDate1,
            end_time: this.endDate1
          }
        })
        .then(res => {
          let that = this;
          if (res.data.code == 0) {
            this.FansEchart.yData1 = res.data.data.datas1;
            this.FansEchart.yData2 = res.data.data.datas2;
            res.data.data.dates.forEach((item, index) => {
              that.FansEchart.xData.push(that.timestamp(item, "Y-M-D"));
              return that.FansEchart.xData;
            });

          }
        });
    },

    // 获取左侧点赞趋势图表数据
    getFabulousEchart() {
      switch (this.FabulousDays) {
        case "近7天":
          this.endDate2 = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate2 = this.timestamp(
            Date.now() / 1000 - 86400 * 6,
            "Y-M-D"
          );
          break;
        case "30天":
          this.endDate2 = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate2 = this.timestamp(
            Date.now() / 1000 - 86400 * 29,
            "Y-M-D"
          );
          break;
        case "90天":
          this.endDate2 = this.timestamp(Date.now() / 1000, "Y-M-D");
          this.startDate2 = this.timestamp(
            Date.now() / 1000 - 86400 * 89,
            "Y-M-D"
          );
          break;
        default:
          this.startDate2 = this.FabulousliveTime[0];
          this.endDate2 = this.FabulousliveTime[1];
          break;
      }
      this.FabulousliveTime = [this.startDate2, this.endDate2];
      this.$axios
        .get("/api/Author/GetFansFavoriteTrend", {
          params: {
            AuthorId: this.authorId,
            trendType: 2,
            star_time: this.startDate2,
            end_time: this.endDate2
          }
        })
        .then(res => {
          this.FabulousEchart.yData1 = res.data.data.datas1;
          this.FabulousEchart.yData2 = res.data.data.datas2;
          res.data.data.dates.forEach((item, index) => {
            this.FabulousEchart.xData.push(this.timestamp(item, "Y-M-D"));
            return this.FabulousEchart.xData;
          });
        });
    },
    // 收藏
    addStar() {
      let that = this;
      that.$axios
        .post(
          "/api/collection/InsertCollection",
          {
            CollectId: that.authorId,
            Module: 1 //模块 1达人 2视频 3音乐 4话题 5商品
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel != null) {
                that.cancel();
              }
              that.cancel = c;
            })
          }
        )
        .then(res => {
          if (res.data.code == 0) {
            that.infoData.isCollect = 1;
            this.$message({
              message: "收藏成功",
              duration: 2000,
              type: "success",
              offset: 154
            });
          }else if(res.data.code == 1003){
            this.storeUpMask = true
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 取消收藏
    cancelStar() {
      let that = this;
      that.$axios
        .post(
          "/api/collection/CancelCollection",
          {
            CollectId: that.authorId,
            Module: 1 //模块 1达人 2视频 3音乐 4话题 5商品
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel01 != null) {
                that.cancel01();
              }
              that.cancel01 = c;
            })
          }
        )
        .then(res => {
          if (res.data.code == 0) {
            that.infoData.isCollect = 0;
            this.$message({
              message: "取消收藏成功",
              duration: 2000,
              type: "success",
              offset: 154
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 回到顶部方法
    backTop() {
      document.body.scrollTop = document.documentElement.scrollTop = 0;
    },
    // 获取左侧详情数据
    getInfoData() {
      return new Promise((resolve, reject) => {
        let that = this;
        that.finishLeft = false;
        this.$axios
          .get("/api/Author/GetAuthorDetailInfo", {
            params: {
              authorId: that.authorId,
              "api-version": 2,
              realTime: 0  //0 默认历史数据 1 爬虫实时数据
            }
          })
          .then(res => {
            if (res.data.code == 0) {
              that.infoData = res.data.data;
              that.finishLeft = true;
              document.title = res.data.data.nickName + "-达人数据|粉丝|视频|直播数据分析-掌上精选";
              this.realTime = 1;
              resolve(res.data.code);
            } else {
              reject(res.data.code);
            }
          })
          .catch(err => {
            reject(res.data.code);
            console.log(err);
          });
      });
    },
    getInfoData1() {
      let that = this;
      this.$axios
        .get("/api/Author/GetAuthorDetailInfo", {
          params: {
            authorId: that.authorId,
            "api-version": 2,
            realTime: 1,  //0 默认历史数据 1 爬虫实时数据
          }
        })
        .then(res => {
          if (res.data.code == 0) {
            that.infoData = res.data.data;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    toRankPage(index, item1) {

      let str1 = "";
      let str2 = "";
      if (index == 1) {
        str1 = item1.match(/(\S*)排行榜/)[1];
        str2 = item1.match(/排行榜(\S*)第/)[1];
      }
      // console.log('str1', str1)
      // console.log('str2', str2)
      this.$router.push({
        path: `/talent_main/fans_main/${index}/${str1}/${str2}`
      });
    },
    // 带货口碑
    // getPublicPraiseTrend() {
    //   this.$axios
    //     .get("/api/Author/GetPublicPraiseTrend", {
    //       params: {
    //         authorId: this.authorId,
    //         trendType: this.trendType
    //       }
    //     })
    //     .then(res => { })
    //     .catch(err => {
    //       console.log(err);
    //     });
    // },
    // 添加对比
    addCompare(val) {
      // 判断当前数组长度 需小于6

      if (this.num < 6) {
        let a = this.taentNewData.every((el, index) => {
          return el.authorId != val.authorId;
        });

        if (a) {
          const newData = JSON.parse(
            localStorage.getItem("TalentDetails_Contrast")
          );
          if (newData) {
            newData.push(val);
            localStorage.setItem(
              "TalentDetails_Contrast",
              JSON.stringify(newData)
            );
          } else {
            localStorage.setItem("TalentDetails_Contrast", JSON.stringify([]));
            const newData2 = JSON.parse(
              localStorage.getItem("TalentDetails_Contrast")
            );
            newData2.push(val);
            localStorage.setItem(
              "TalentDetails_Contrast",
              JSON.stringify(newData2)
            );
          }
          this.taentNewData = JSON.parse(
            localStorage.getItem("TalentDetails_Contrast")
          );
          // 存id
          let compareArr = [];
          if (JSON.parse(localStorage.getItem("TalentDetails_Contrast_id"))) {
            compareArr = JSON.parse(
              localStorage.getItem("TalentDetails_Contrast_id")
            );
          }
          compareArr.push(val.authorId);
          localStorage.setItem(
            "TalentDetails_Contrast_id",
            JSON.stringify(compareArr)
          );

          this.num = this.taentNewData.length;
        } else {
          this.taentNewData.forEach((item, index) => {
            if (item.authorId == val.authorId) {
              // 删除id
              let delIndex = JSON.parse(
                localStorage.getItem("TalentDetails_Contrast_id")
              ).findIndex(i => i == item.authorId);
              let inCompareList = JSON.parse(
                localStorage.getItem("TalentDetails_Contrast_id")
              );
              inCompareList.splice(delIndex, 1);
              localStorage.setItem(
                "TalentDetails_Contrast_id",
                JSON.stringify(inCompareList)
              );

              this.taentNewData.splice(index, 1);
              localStorage.setItem(
                "TalentDetails_Contrast",
                JSON.stringify(this.taentNewData)
              );
              this.taentNewData = JSON.parse(
                localStorage.getItem("TalentDetails_Contrast")
              );
            }
            this.num = this.taentNewData.length;
          });
        }
      } else {
        this.taentNewData.forEach((item, index) => {
          let b = this.taentNewData.every((el, index) => {
            return el.authorId != val.authorId;
          });
          if (!b) {
            if (item.authorId == val.authorId) {
              // 删除id
              let delIndex = JSON.parse(
                localStorage.getItem("TalentDetails_Contrast_id")
              ).findIndex(i => i == item.authorId);
              let inCompareList = JSON.parse(
                localStorage.getItem("TalentDetails_Contrast_id")
              );
              inCompareList.splice(delIndex, 1);
              localStorage.setItem(
                "TalentDetails_Contrast_id",
                JSON.stringify(inCompareList)
              );

              this.taentNewData.splice(index, 1);
              localStorage.setItem(
                "TalentDetails_Contrast",
                JSON.stringify(this.taentNewData)
              );
              this.taentNewData = JSON.parse(
                localStorage.getItem("TalentDetails_Contrast")
              );
              this.num = this.taentNewData.length;
            }
          } else {
            if (document.getElementsByClassName("el-message").length === 0) {
              this.$message({
                message: "对比达人数不得超过6人",
                center: true,
                duration: 1500,
                offset: 444,
                type: "warning"
              });
            }
          }
        });
      }
    },
    // 鼠标移入显示删除按钮
    mouseOver(item, index) {
      this.isShowImg = item.authorId;
    },
    // 鼠标移入隐藏删除按钮
    mouseleave() {
      this.isShowImg = "";
    },
    // 点击×删除单个达人
    deleteTalent(id) {
      this.taentNewData.forEach((item, index) => {
        if (item.authorId == id) {
          this.taentNewData.splice(index, 1);
          let delIndex = JSON.parse(
            localStorage.getItem("TalentDetails_Contrast_id")
          ).findIndex(i => i == item.authorId);
          let inCompareList = JSON.parse(
            localStorage.getItem("TalentDetails_Contrast_id")
          );
          inCompareList.splice(delIndex, 1);
          localStorage.setItem(
            "TalentDetails_Contrast_id",
            JSON.stringify(inCompareList)
          );
          localStorage.setItem(
            "TalentDetails_Contrast",
            JSON.stringify(this.taentNewData)
          );
          this.taentNewData = JSON.parse(
            localStorage.getItem("TalentDetails_Contrast")
          );
          this.num = this.taentNewData.length;
        }
      });
    },
    // 清空
    empty() {
      this.taentNewData = [];
      localStorage.setItem(
        "TalentDetails_Contrast",
        JSON.stringify(this.taentNewData)
      );
      localStorage.setItem("TalentDetails_Contrast_id", JSON.stringify([]));
      this.num = this.taentNewData.length;
    },
    // 确认对比
    comparison() {
      this.$axios
        .get("/api/customer/GetNumberofvisitsDetailed", {
          params: {
            API: "/api/author/addcompare"
          }
        })
        .then(res => {
          if (res.data.code == 0) {
            this.surplusCount = res.data.data.surplusCount;
          }
          if (res.data.data.surplusCount) {
            this.showButton = true;
            this.showLoading1 = true;
            this.$axios
              .get("/api/author/addcompare?api-version=2", {
                params: {
                  author_ids: JSON.parse(
                    localStorage.getItem("TalentDetails_Contrast_id")
                  ).join(",")
                }
              })
              .then(res => {
                if (res.data.code == 0) {
                  this.showLoading1 = true;
                  this.showButton = false;
                  // this.talentDetails = true;
                  this.empty();
                  this.$router.push({
                    path: "/talent_main/compare",
                    query: { data: "3" }
                  });

                  // 对比详情展示
                  // this.item_id = res.data.data;
                }
              })
              .catch(err => {
                console.log(err);
              });
          } else {
            this.$message({
              message: "您的对比次数已用完，请升级您的会员等级。",
              duration: 2000,
              customClass: "includeMessage",
              offset: 154
            });
          }
        });
    },
    ////////////   一键提速   /////////////////
    // 一键提速调时间
    getTimeDown() {
      if (this.textNum == "" || this.textNum == "1") {
        this.$axios
          .get("/api/Author/OneClickSpeedUp", {
            params: {
              authorId: this.authorId,
            }
            //isShop: this.infoData.isShop
          }).then(res => {
            if (res.data.code == 0) {
              this.timeDown = res.data.data.time;
              this.timeAuthor = res.data.data.authorId;
              if (this.timeAuthor == this.authorId) {
                if (this.timeDown > 10 * 60 * 1000) {
                  this.textNum = 1;
                  this.timeDown = this.timeDown - 10 * 60 * 1000;
                  this.showBall = false
                  this.speedIs = true
                  this.loopTime = setInterval(() => {
                    this.isOpacity = !this.isOpacity;
                    this.minute = Math.floor((this.timeDown / 1000 / 60) % 60);
                    this.secondS = Math.floor((this.timeDown / 1000) % 60);
                    this.minute = this.minute < 10 ? "0" + this.minute : this.minute;
                    this.secondS = this.secondS < 10 ? "0" + this.secondS : this.secondS;
                    this.timeDown -= 1000;
                  }, 1000);
                } else {
                  this.textNum = 2;
                  this.showBall = true;

                  this.speedIs = false;
                  this.fivemin = false;
                  this.tenmin = false;
                  if (res.data.data.status == 0) {
                    this.keyss = 1;
                  } else {
                    this.keyss = 2
                      ;
                  }
                  this.loopTenTime = setInterval(() => {
                    this.minute = Math.floor(
                      (this.timeDown / 1000 / 60) % 60
                    );
                    this.secondS = Math.floor((this.timeDown / 1000) % 60);
                    this.minute =
                      this.minute < 10 ? "0" + this.minute : this.minute;
                    this.secondS =
                      this.secondS < 10 ? "0" + this.secondS : this.secondS;
                    this.timeDown -= 1000;
                  }, 1000);
                }
              } else {
                this.$message({
                  message: '已有达人正在提速中，请稍后再试！',
                  type: 'warning',
                  duration: 2000,
                  offset: '400'
                });

              }
            }
          })
      } else {
        this.showBall = false;
        this.speedIs = false;
        this.fivemin = false;
        this.tenmin = true;
      }
    },

    // 加速中
    speedIngChang() {
      this.fivemin = true;
      this.showBall = false;
      this.speedIs = false;
    },
    // 关闭按钮
    closeimg() {
      this.fivemin = false;
      this.speedIs = true;
    },
    closeimg2() {
      this.tenmin = false;
      this.showBall = true;
      this.keyss = 1;
    }
  },
  beforeDestroy() {
    clearInterval(this.speedShowTime);

  }

};
